#include <Arduino.h>
#include <U8g2lib.h>

// #ifdef U8X8_HAVE_HW_SPI
// #include <SPI.h>
// #endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif

//create oled driver lib
// U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE);
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);

typedef unsigned char uchar;
typedef unsigned long ulong;

//ds18b20 pin define,不能用带PWM的口
const uint8_t DQ=2;

bool isComplete=false;
bool isSetting=false;
String reciveStr="";
const char* menuItem[] PROGMEM={"SETTING","TEST"};

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  //init oled
  u8g2.begin();
  u8g2_prepare();
}

void u8g2_prepare() {
  u8g2.enableUTF8Print();
  u8g2.setContrast(10);
  // u8g2.setFont(u8g2_font_unifont_t_chinese3);
  u8g2.setFont(u8g2_font_ncenB08_tr);
  u8g2.setFontRefHeightExtendedText();
  u8g2.setDrawColor(1);
  u8g2.setFontPosTop();
  u8g2.setFontDirection(0);
}

void loop() {
  // put your main code here, to run repeatedly:
  if(isComplete){
    Serial.println(reciveStr);
    isSetting=true;
    u8g2.firstPage();
    do{
      switch(49){
        case 'a':
          for(uchar i=0;i<2;i++){
            u8g2.drawStr(0,(i*16)+1,"11111");
          }
        default:
          break;    
      }
    }while(u8g2.nextPage());
    isComplete=false;
    return;
  }
  if(isSetting){
    return;
  }
  //show home
}

void serialEvent(){
  while(Serial.available()>0){
    char recivceByte=(char)Serial.read();
    if(recivceByte!='\n'){
      reciveStr += recivceByte;
      isComplete=true;
    }
  }
}


